package com.opencvjava.lessons.imgproc;

import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import org.springframework.stereotype.Service;

import static com.opencvjava.support.util.CvUtils.imshow;
import static com.opencvjava.support.util.CvUtils.mat;
import static org.opencv.imgproc.Imgproc.Canny;
import static org.opencv.imgproc.Imgproc.blur;

@Service
public class L12_Canny {
    public void test() {
        Mat src = mat("lena.jpg");
        imshow("源图", src);
        Mat srcBlur = new Mat();
        Mat detectedEdges = new Mat();
        blur(src, srcBlur, new Size(5, 5));
        Canny(srcBlur, detectedEdges, 50, 200, 5, false);
        Mat dst = new Mat(src.size(), CvType.CV_8UC3, Scalar.all(0));
        src.copyTo(dst, detectedEdges);
        imshow("结果0", detectedEdges);
        imshow("结果1", dst);
    }
}
